using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using SoinusLibrary.Data;
using SoinusLibrary;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class LoginWS : System.Web.Services.WebService
{
    public LoginWS () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public bool AuthenticateUser(String email, String pass)
    {
        return SoinusDBM.Instance.Authenticate(email, pass);
    }

    [WebMethod]
    public bool AuthenticateUserGUID(String email, String pass, out Guid guid)
    {
        bool result = false;
        guid = Guid.Empty;

        if (SoinusDBM.Instance.Authenticate(email, pass))
        {
            guid = SoinusDBM.Instance.GetUserGUID(email);
            result = true;
        }

        return result;
    }

    [WebMethod]
    public int RegisterUser(String email, String pass)
    {
        int result = -1;

        if (!UserExists(email))
        {
            if (SoinusDBM.Instance.RegisterUser(email, pass))
            {
                result = Message.OK;
            }
            else
            {
                result = Message.ERROR_REGISTER;
            }
        }
        else
        {
            result = Message.ERROR_USER_EXISTS;
        }
        return result;
    }

    [WebMethod]
    public bool UserExists(String email)
    {
        bool result = false;

        if (SoinusDBM.Instance.UserExists(email))
            result = true;
        else
            result = false;

        return result;
    }
    
}
